package com.letv.android.client.album.controller;

import android.os.Handler;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.letv.android.young.client.R;
import com.letv.android.client.activity.AlbumPlayRoomActivity;
import com.letv.business.flow.album.AlbumPlayFlow;
import com.letv.business.flow.album.listener.AlbumVipTrailListener;
import com.letv.business.flow.album.model.AlbumPlayInfo;
import com.letv.core.api.LetvRequest;
import com.letv.core.api.LetvUrlMaker;
import com.letv.core.api.UrlConstdata.USE_TICKET;
import com.letv.core.bean.DataHull;
import com.letv.core.bean.TicketUseBean;
import com.letv.core.db.PreferencesManager;
import com.letv.core.network.volley.VolleyRequest;
import com.letv.core.network.volley.VolleyRequest.RequestManner;
import com.letv.core.network.volley.VolleyResponse.NetworkResponseState;
import com.letv.core.network.volley.toolbox.SimpleResponse;
import com.letv.core.network.volley.toolbox.VolleyNoCache;
import com.letv.core.parser.TicketUseParser;
import com.letv.core.utils.LetvTools;
import com.letv.core.utils.LogInfo;
import com.letv.core.utils.StatisticsUtils;
import com.letv.core.utils.TipUtils;
import com.letv.core.utils.UIsUtils;
import com.letv.datastatistics.DataStatistics;
import com.letv.datastatistics.util.LetvErrorCode;
import com.letv.datastatistics.util.PageIdConstant;

import com.ledim.utils.ToastUtil;
import java.util.HashMap;
import java.util.Map;

//import com.letv.android.client.activity.LetvLoginActivity;
//import com.letv.android.client.activity.VipProductsActivity;

/**
 * 点播会员提示控制器
 * 
 * @author zhuqiao
 *
 */
public class AlbumRoomPlayVipTrailController implements OnClickListener, AlbumVipTrailListener {
    private static final int START_VIEW_DURATION = 7 * 1000;

    private AlbumPlayRoomActivity mActivity;

    private View mFrame;

    // --------------- 提示浮层 ---------------
    /** 付费视频，试看开始提示view **/
    private View mStartView;
    /** 付费视频，试看结束view **/
    private View mEndView;
    /** 使用观影券结果提示view **/
    private View mUseTicketReultView;
    private View mForbiddenView;

    // --------------- 试看开始布局 ---------------
    /** 试看开始并提示开通会员view **/
    private View mStartBuyVipView;
    /** 试看开始并提示开通会员view(两个btn) **/
    private View mStartBuyVipBtnsView;
    /** 试看开始使用观影券张数提示view **/
    private View mStartUseTicketView;
    /** 试看开始使用观影券张数提示view(一个btn) **/
    private View mStartUseTicketBtnsView;
    /** 试看开始观影券已用完提示view **/
    private View mStartTicketNoneView;

    // --------------- 试看结束局部 ---------------
    /** 试看结束并提示开通会员view **/
    private View mEndBuyVipView;
    /** 试看结束已成为会员提示view **/
    private View mEndUseTicketView;
    /** 试看结束观影券已用完提示view **/
    private View mEndTicketNoneView;

    // --------------- 按钮 ---------------
    /** 试看开始开通会员按钮 **/
    private View mStartBuyVipBtn;
    /** 试看开始登录按钮 **/
    private View mStartLoginBtn;
    /** 试看结束开通会员按钮 **/
    private Button mEndBuyBtn;
    /** 试看结束登录按钮 **/
    private View mEndLoginBtn;

    /** 试看开始点击使用观影券按钮 **/
    private View mStartUseTicketBtn;
    /** 试看结束点击使用观影券按钮 **/
    private View mEndUseTicketBtn;

    /** 试看结束，提示还有xx张文案TextView **/
    private TextView mEndUseTicketTextView;
    /** 封禁title **/
    private TextView mForbiddenTitleView;
    /** 封禁msg **/
    private TextView mForbiddenMsgView;

    /** 观影券张数 **/
    private int mTicketSize;
    /** 0:点播;1:点播且包月;2:包月 **/
    @SuppressWarnings("unused")
    private int mChargeType;

    private VipTrailErrorState mErrState = VipTrailErrorState.INIT;
    private boolean mIsVipTrailEnd = false;

    /** 是否可以播放 **/
    private boolean mCanPlay = true;

    /** 试看开始并提示开通会员view显示状态 **/
    private ShowState mStartBuyViewShowState = ShowState.NOT_SHOWED;
    private ShowState mStartTicketViewShowState = ShowState.NOT_SHOWED;
    private ShowState mStartNoTicketViewShowState = ShowState.NOT_SHOWED;

    /** 控制条是否显示中 **/
    private boolean mIsControllerVisible = true;

    public enum ShowState {
        /**
         * 未显示过
         */
        NOT_SHOWED,
        /**
         * 显示中
         */
        SHOWING,
        /**
         * 显示过了
         */
        HAS_SHOWED
    }

    private Handler mHandler = new Handler();

    /**
     * 点击回调
     */
    public interface VipTrailLayoutListener {
        void onTrailBuyVip(boolean isLogin, boolean isTrailOver);

        void onTrailUseTicket();

        void onTrailBack();

        void onTrailHalfFull();
    }

    public AlbumRoomPlayVipTrailController(AlbumPlayRoomActivity activity) {
        mActivity = activity;
        init();
    }

    private void init() {
        mFrame = mActivity.findViewById(R.id.vip_trail_frame);

        mStartView = mActivity.findViewById(R.id.vip_trail_start);
        mEndView = mActivity.findViewById(R.id.vip_trail_end);
        mUseTicketReultView = mActivity.findViewById(R.id.vip_trail_use_ticket_result);

        mStartBuyVipView = mActivity.findViewById(R.id.vip_trail_start_buy_vip);
        mStartBuyVipBtnsView = mActivity.findViewById(R.id.vip_trail_start_buy_vip_btns);
        mStartUseTicketView = mActivity.findViewById(R.id.vip_trail_start_use_ticket);
        mStartUseTicketBtnsView = mActivity.findViewById(R.id.vip_trail_start_use_ticket_btns);
        mStartTicketNoneView = mActivity.findViewById(R.id.vip_trail_start_ticket_none);

        mEndBuyVipView = mActivity.findViewById(R.id.vip_trail_end_buy_vip);
        mEndUseTicketView = mActivity.findViewById(R.id.vip_trail_end_use_ticket);
        mEndTicketNoneView = mActivity.findViewById(R.id.vip_trail_end_ticket_none);

        mStartBuyVipBtn = mActivity.findViewById(R.id.vip_trail_start_buy_vip_button1);
        mStartLoginBtn = mActivity.findViewById(R.id.vip_trail_start_buy_vip_button2);
        mEndBuyBtn = (Button) mActivity.findViewById(R.id.vip_trail_end_buy_vip_btn);
        mEndLoginBtn = mActivity.findViewById(R.id.vip_trail_end_buy_vip_login_btn);

        mStartUseTicketBtn = mActivity.findViewById(R.id.vip_trail_start_use_ticket_btn);
        mEndUseTicketBtn = mActivity.findViewById(R.id.vip_trail_end_use_ticket_btn);

        mForbiddenView = mActivity.findViewById(R.id.vip_trail_forbidden);
        mForbiddenTitleView = (TextView) mActivity.findViewById(R.id.vip_trail_forbidden_title);
        mForbiddenMsgView = (TextView) mActivity.findViewById(R.id.vip_trail_forbidden_msg);

        ((TextView) mActivity.findViewById(R.id.vip_trail_start_text_header)).setText(mActivity.getString(
                R.string.vip_trail_start_text_header, PreferencesManager.getInstance(mActivity).getVipTrailTime()));
        mForbiddenTitleView.setText(TipUtils.getTipMessage(mActivity,"100078", R.string.vip_trail_forbidden_title));
        mForbiddenMsgView.setText(TipUtils.getTipMessage(mActivity,"100079", R.string.vip_trail_forbidden_desc));

        initClick();
    }

    private void initClick() {
        mStartBuyVipBtn.setOnClickListener(this);
        mStartLoginBtn.setOnClickListener(this);
        mEndBuyBtn.setOnClickListener(this);
        mEndLoginBtn.setOnClickListener(this);
        mStartUseTicketBtn.setOnClickListener(this);
        mEndUseTicketBtn.setOnClickListener(this);
        mEndView.setOnClickListener(this);
        mForbiddenView.setOnClickListener(this);

        mActivity.findViewById(R.id.vip_trail_start_buy_vip_btns_button1).setOnClickListener(this);
        mActivity.findViewById(R.id.vip_trail_start_buy_vip_btns_button2).setOnClickListener(this);
        mActivity.findViewById(R.id.vip_trail_start_use_ticket_btns).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.vip_trail_start_buy_vip_button1 || id == R.id.vip_trail_start_buy_vip_btns_button1) {
            // 试看开始购买会员
            onTrailBuyVip(true, false);
        }
        else if (id == R.id.vip_trail_start_buy_vip_button2 || id == R.id.vip_trail_start_buy_vip_btns_button2) {
            // 试看开始登录
            onTrailBuyVip(false, false);
        }
        else if (id == R.id.vip_trail_end_buy_vip_btn) {
            // 试看结束购买会员
            onTrailBuyVip(true, true);
        }
        else if (id == R.id.vip_trail_end_buy_vip_login_btn) {
            // 试看结束登录
            onTrailBuyVip(false, true);
        }
        else if (id == R.id.vip_trail_start_use_ticket_btn || id == R.id.vip_trail_start_use_ticket_btns
            || id == R.id.vip_trail_end_use_ticket_btn) {
            // 试看结束使用观影券
            requestUseTicket();
        }
        else if (id == R.id.vip_trail_end || id == R.id.vip_trail_forbidden) {
        }
        else {
        }
    }

    /**
     * 点击开通vip和登录
     * 
     * @param isLogin
     * @param isTrailOver
     */
    private void onTrailBuyVip(boolean isLogin, boolean isTrailOver) {
        if (mActivity.getFlow() == null) {
            return;
        }

        AlbumPlayFlow flow = mActivity.getFlow();

//        if (isLogin) {
//            VipProductsActivity.launchFromPlay(mActivity, mActivity.getString(R.string.pim_vip_good_title),
//                    flow.getAid(), flow.getVid());
//            // 统计
//            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c62", "0022", -1, null,
//                    UIsUtils.isLandscape(mActivity) ? PageIdConstant.fullPlayPage : PageIdConstant.halpPlayPage,
//                    String.valueOf(mActivity.getFlow().getCid()), null, null, null, null);
//        } else {
//            LetvLoginActivity.launch(mActivity, PlayConstant.FORPLAY, LoginConstant.ALBUM_REQUEST_CODE_PLAY_LOGIN);
//            // 统计
//            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c62", "0020", -1, null,
//                    UIsUtils.isLandscape(mActivity) ? PageIdConstant.fullPlayPage : PageIdConstant.halpPlayPage,
//                    String.valueOf(mActivity.getFlow().getCid()), null, null, null, null);
//        }
    }

    /**
     * 请求观影券使用
     */
    private void requestUseTicket() {
        if (mActivity.getFlow() == null || mActivity.getLoadListener() == null) {
            return;
        }

        final AlbumPlayFlow flow = mActivity.getFlow();

        mActivity.getLoadListener().loading(false);

        String userid = PreferencesManager.getInstance(mActivity).getUserId();
        String name = "";
        if (flow.getAlbum() != null) {
            name = flow.getAlbum().getNameCn();
        } else if (flow.getPlayingVideo() != null) {
            name = flow.getPlayingVideo().getNameCn();
        }

        Map<String, String> postParams = new HashMap<String, String>();
        postParams.put(USE_TICKET.USERID, userid);
        postParams.put(USE_TICKET.PID, flow.getAid() + "");
        postParams.put(USE_TICKET.NAME, name);
        postParams.put(USE_TICKET.SIGN, LetvTools.generateSignKey(userid, flow.getAid() + ""));

        new LetvRequest<TicketUseBean>(mActivity).setUrl(LetvUrlMaker.getUseTicketUrl(mActivity)).setCache(new VolleyNoCache())
                .setRequestType(RequestManner.NETWORK_ONLY).addPostParams(postParams).setParser(new TicketUseParser())
                .setCallback(new SimpleResponse<TicketUseBean>() {

                    @Override
                    public void onNetworkResponse(VolleyRequest<TicketUseBean> request, TicketUseBean result,
                            DataHull hull, NetworkResponseState state) {
                        if (state == NetworkResponseState.SUCCESS) {
                            if (result.getCode() == 0) {
                                vipTrailUseTicketSuccess();
                                if (mActivity.getFlow()!=null) {
                                    mActivity.getFlow().retryPlay(false, false);
                                }
                                // wuxinrong 2015-08-15 added begin
                                mActivity.getFullControllerFragment().updateWindowPlayStatus();
                                // wuxinrong 2015-08-15 added end
                            } else {
                                mActivity.getLoadListener().finish();
                                String failedMsg = mActivity.getString(R.string.vip_trail_ticket_use_failed);
                                if (!TextUtils.isEmpty(result.getMsg())) {
                                    failedMsg += ":" + result.getMsg();
                                }
                                ToastUtil.toast(failedMsg);
                            }
                        } else if (state == NetworkResponseState.NETWORK_NOT_AVAILABLE
                                || state == NetworkResponseState.NETWORK_ERROR
                                || state == NetworkResponseState.RESULT_ERROR) {
                            if (state != NetworkResponseState.NETWORK_NOT_AVAILABLE) {
                                ToastUtil.toast(R.string.vip_trail_ticket_use_failed);
                            }

                            mActivity.getLoadListener().requestError("", "");
                            hide();
                            flow.setPlayCallBackState(8);
                        }
                    }

                    @Override
                    public void onErrorReport(VolleyRequest<TicketUseBean> request, String errorInfo) {
                        // 统计
                        DataStatistics.getInstance().sendErrorInfo(mActivity, "0", "0",
                                LetvErrorCode.LTURLModule_UC_UseVoucher, null, errorInfo, null, null, null, null);
                    }

                }).add();
    }

    // ------------------------- AlbumVipTrailListener实现 -------------------------

    private void vipTrailStart() {
        mIsVipTrailEnd = false;
        switch (mErrState) {
            case START_WITH_LOGIN:
                showStartBuyVip(true);
                break;
            case START_WITH_NOT_LOGIN:
                showStartBuyVip(false);
                break;
            case START_WITH_TICKET:
                showStartByTicket(true);
                break;
            case START_WITH_NOT_TICKET:
                showStartByTicket(false);
                break;
            default:
                break;
        }
    }

    @Override
    public void setStateForStartByHasLogined(boolean hasLogined) {
        mErrState = hasLogined ? VipTrailErrorState.START_WITH_LOGIN : VipTrailErrorState.START_WITH_NOT_LOGIN;

        showStartBuyVip(hasLogined);
    }

    @Override
    public void setStateForStartByHasTicket(boolean hasTicket) {
        mErrState = hasTicket ? VipTrailErrorState.START_WITH_TICKET : VipTrailErrorState.START_WITH_NOT_TICKET;

        showStartByTicket(hasTicket);
    }

    private void showStartBuyVip(boolean hasLogined) {
        mActivity.findViewById(R.id.vip_trail_start_buy_vip_text2).setVisibility(hasLogined ? View.GONE : View.VISIBLE);
        mStartLoginBtn.setVisibility(hasLogined ? View.GONE : View.VISIBLE);
        mActivity.findViewById(R.id.vip_trail_start_buy_vip_btns_button2).setVisibility(
                hasLogined ? View.GONE : View.VISIBLE);
        vipTrailStartInit();

        if (mStartBuyViewShowState == ShowState.SHOWING) {
            return;
        }

        if (mStartBuyViewShowState == ShowState.HAS_SHOWED) {
            mStartBuyVipView.setVisibility(View.GONE);
            mStartBuyVipBtnsView.setVisibility(View.VISIBLE);
            return;
        }

        mStartBuyVipView.setVisibility(View.VISIBLE);
        mStartUseTicketView.setVisibility(View.GONE);
        mStartUseTicketBtnsView.setVisibility(View.GONE);
        mStartTicketNoneView.setVisibility(View.GONE);

        if (mIsControllerVisible) {
            return;
        }

        mStartBuyViewShowState = ShowState.SHOWING;
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                mStartBuyViewShowState = ShowState.HAS_SHOWED;
                mStartBuyVipView.setVisibility(View.GONE);
                mStartBuyVipBtnsView.setVisibility(View.VISIBLE);
            }
        }, START_VIEW_DURATION);
    }

    private void showStartByTicket(boolean hasTicket) {
        if (hasTicket) {
            // 有观影券
            if (mStartTicketViewShowState == ShowState.SHOWING) {
                return;
            }
            if (mStartTicketViewShowState == ShowState.HAS_SHOWED) {
                mStartUseTicketView.setVisibility(View.GONE);
                mStartUseTicketBtnsView.setVisibility(View.VISIBLE);
                return;
            }

            vipTrailStartInit();

            mStartBuyVipView.setVisibility(View.GONE);
            mStartBuyVipBtnsView.setVisibility(View.GONE);
            mStartUseTicketView.setVisibility(View.VISIBLE);
            mStartTicketNoneView.setVisibility(View.GONE);

            if (mIsControllerVisible) {
                return;
            }

            mStartTicketViewShowState = ShowState.SHOWING;
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mStartTicketViewShowState = ShowState.HAS_SHOWED;
                    mStartUseTicketView.setVisibility(View.GONE);
                    mStartUseTicketBtnsView.setVisibility(View.VISIBLE);
                }
            }, START_VIEW_DURATION);
        } else {
            // 没有观影券
            if (mStartNoTicketViewShowState == ShowState.SHOWING || mStartNoTicketViewShowState == ShowState.HAS_SHOWED) {
                return;
            }

            vipTrailStartInit();

            mStartNoTicketViewShowState = ShowState.SHOWING;
            mStartBuyVipView.setVisibility(View.GONE);
            mStartBuyVipBtnsView.setVisibility(View.GONE);
            mStartUseTicketView.setVisibility(View.GONE);
            mStartTicketNoneView.setVisibility(View.VISIBLE);

            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mStartNoTicketViewShowState = ShowState.HAS_SHOWED;
                    mStartTicketNoneView.setVisibility(View.GONE);
                }
            }, START_VIEW_DURATION);
        }
    }

    private void vipTrailEnd() {
        mIsVipTrailEnd = true;
        switch (mErrState) {
            case START_WITH_LOGIN:
            case END_WITH_LOGIN:
                vipTrailEndByHasLogined(true);
                break;
            case START_WITH_NOT_LOGIN:
            case END_WITH_NOT_LOGIN:
                vipTrailEndByHasLogined(false);
                break;
            case START_WITH_TICKET:
            case END_WITH_TICKET:
                vipTrailEndByHasTicket(true);
                break;
            case START_WITH_NOT_TICKET:
            case END_WITH_NOT_TICKET:
                vipTrailEndByHasTicket(false);
                break;
            default:
                break;
        }
    }

    @Override
    public void vipTrailEndByHasLogined(boolean hasLogined) {
        mErrState = hasLogined ? VipTrailErrorState.END_WITH_LOGIN : VipTrailErrorState.END_WITH_NOT_LOGIN;

        vipTrailEndInit();
        mEndBuyVipView.setVisibility(View.VISIBLE);
        mEndUseTicketView.setVisibility(View.GONE);
        mEndTicketNoneView.setVisibility(View.GONE);

        mEndLoginBtn.setVisibility(hasLogined ? View.GONE : View.VISIBLE);
        mActivity.findViewById(R.id.vip_trail_end_buy_vip_login_frame).setVisibility(
                hasLogined ? View.GONE : View.VISIBLE);

        // if (mChargeType != 0) {
        // mEndBuyBtn.setText(R.string.vip_trail_end_buy_vip_chargetype_0);
        // }

        // 统计
        LogInfo.log("zhuqiao", "试看结束提示浮层曝光--" + (hasLogined ? "用户已登陆" : "用户未登陆"));
        StatisticsUtils.staticticsInfoPost(mActivity, "19", "c62", null, -1, null,
                UIsUtils.isLandscape(mActivity) ? PageIdConstant.fullPlayPage : PageIdConstant.halpPlayPage, null,
                null, null, null, null);
    }

    @Override
    public void vipTrailEndByHasTicket(boolean hasTicket) {
        mErrState = hasTicket ? VipTrailErrorState.END_WITH_TICKET : VipTrailErrorState.END_WITH_NOT_TICKET;

        vipTrailEndInit();
        mEndBuyVipView.setVisibility(View.GONE);
        mEndUseTicketView.setVisibility(hasTicket ? View.VISIBLE : View.GONE);
        mEndTicketNoneView.setVisibility(hasTicket ? View.GONE : View.VISIBLE);

        if (!hasTicket)
            return;

        // 设置还有xx张
        mEndUseTicketTextView = (TextView) mActivity.findViewById(R.id.vip_trail_end_use_ticket_text2);
        String str = String.format(mActivity.getString(R.string.vip_trail_over_use_ticket_text2), mTicketSize);
        SpannableStringBuilder style = new SpannableStringBuilder(str);
        style.setSpan(new ForegroundColorSpan(mActivity.getResources().getColor(R.color.letv_color_ffec8e1f)), 8,
                8 + String.valueOf(mTicketSize).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mEndUseTicketTextView.setText(style);
    }

    @Override
    public void vipTrailBackTitleScreenProcess(String title, boolean isDolby) {
        AlbumRoomErrorTopController topController = mActivity.getErrorTopController();
        if (topController == null) {
            return;
        }

        topController.show();
        topController.setTitle(title);

        if (isDolby) {
            mActivity.getErrorTopController().setVisibilityForSwitchView(View.GONE);
        }
    }

    @Override
    public void vipTrailUseTicketSuccess() {
        mErrState = VipTrailErrorState.INIT;
        mStartView.setVisibility(View.GONE);
        mEndView.setVisibility(View.GONE);
        mForbiddenView.setVisibility(View.GONE);
        mUseTicketReultView.setVisibility(View.VISIBLE);
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                mUseTicketReultView.setVisibility(View.GONE);
            }
        }, 3000);
    }

    @Override
    public boolean isError() {
        if (mEndUseTicketTextView == null) {
            return false;
        }

        return mEndBuyVipView.getVisibility() == View.VISIBLE || mEndUseTicketTextView.getVisibility() == View.VISIBLE
                || mEndTicketNoneView.getVisibility() == View.VISIBLE;
    }

    @Override
    public void hide() {
        if (isShow()) {
            mStartView.setVisibility(View.GONE);
            mEndView.setVisibility(View.GONE);
            mUseTicketReultView.setVisibility(View.GONE);
            mForbiddenView.setVisibility(View.GONE);
        }
    }

    @Override
    public void finish() {
        mIsVipTrailEnd = false;
        mErrState = VipTrailErrorState.INIT;
        hide();
        mActivity.getErrorTopController().hide();
    }

    @Override
    public VipTrailErrorState getErrState() {
        return mErrState;
    }

    @Override
    public boolean isVipTrailEnd() {
        return mIsVipTrailEnd;
    }

    @Override
    public void setChargetype(int chargetype) {
        mChargeType = chargetype;
    }

    @Override
    public void setTicketSize(int ticketSize) {
        mTicketSize = ticketSize;
    }

    @Override
    public boolean checkVipTrailIsStateEnd() {
        mCanPlay = true;

        if (mActivity.getFlow() == null || mActivity.getLoadListener() == null
                || mActivity.getAlbumPlayFragment() == null || mActivity.getController() == null) {
            return false;
        }

        AlbumPlayFlow flow = mActivity.getFlow();
        int trailTime = PreferencesManager.getInstance(mActivity).getVipTrailTime();
        AlbumPlayInfo playInfo = flow.getPlayInfo();

        if (isVipVideo()) {
            mActivity.getLoadListener().finish();
            long playedTime = playInfo.currTime;
            if (flow.isSkip() && playInfo.beginTime > 0) {
                playedTime -= playInfo.beginTime;
            }
            if (playedTime / 1000 > trailTime * 60) {
                mActivity.getController().pause(false);
                mActivity.getAlbumPlayFragment().stopHandlerTime();
                mActivity.getHalfControllerFragment().setVisibility(View.GONE);
                mActivity.getFullControllerFragment().setVisibility(View.GONE);
                if (mErrState == VipTrailErrorState.FORBIDDEN) {
                    showForbiddenView();
                } else {
                    vipTrailEnd();
                }
                setVisibileWithController(true);
                vipTrailBackTitleScreenProcess(
                        flow.getPlayingVideo() != null ? flow.getPlayingVideo().getNameCn() : "", flow.isDolby());

                mCanPlay = false;
                return true;
            } else {
                vipTrailStart();
            }
        }

        return false;
    }

    /**
     * 是否是收费视频
     *
     * @return
     */
    @Override
    public boolean isVipVideo() {
        return mErrState != VipTrailErrorState.INIT;
    }

    @Override
    public void setVisibileWithController(boolean show) {
        if (mCanPlay) {
            mFrame.setVisibility(show ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public void forbidden() {
        mErrState = VipTrailErrorState.FORBIDDEN;
    }

    private void showForbiddenView() {
        mStartView.setVisibility(View.GONE);
        mEndView.setVisibility(View.GONE);
        mUseTicketReultView.setVisibility(View.GONE);
        mForbiddenView.setVisibility(View.VISIBLE);
    }

    public void setIsControllerVisible(boolean isVisible) {
        mIsControllerVisible = isVisible;
        mFrame.setVisibility(isVisible ? View.GONE : View.VISIBLE);
        if (!mIsControllerVisible) {
            vipTrailStart();
        }
    }

    // ------------------------- AlbumVipTrailListener实现 end -------------------------

    private void vipTrailStartInit() {
        mStartView.setVisibility(View.VISIBLE);
        mEndView.setVisibility(View.GONE);
        mUseTicketReultView.setVisibility(View.GONE);
        mForbiddenView.setVisibility(View.GONE);
    }

    private void vipTrailEndInit() {
        mStartView.setVisibility(View.GONE);
        mEndView.setVisibility(View.VISIBLE);
        mUseTicketReultView.setVisibility(View.GONE);
        mForbiddenView.setVisibility(View.GONE);
    }

    /**
     * 是否有显示试看layout
     * 
     * @return
     */
    private boolean isShow() {
        return mStartView.getVisibility() == View.VISIBLE || mEndView.getVisibility() == View.VISIBLE
                || mUseTicketReultView.getVisibility() == View.VISIBLE
                || mForbiddenView.getVisibility() == View.VISIBLE;
    }

    /**
     * 是否处于试看暂停状态
     * 
     * @return
     */
    public boolean isTryLookPause() {
        return mErrState == VipTrailErrorState.END_WITH_LOGIN || mErrState == VipTrailErrorState.END_WITH_NOT_LOGIN
                || mErrState == VipTrailErrorState.END_WITH_NOT_TICKET
                || mErrState == VipTrailErrorState.END_WITH_TICKET;
    }

}
